package com.cci.zkweb.core.model;

import org.zkoss.zul.Treecell;
import org.zkoss.zul.Treeitem;
import org.zkoss.zul.TreeitemRenderer;
import org.zkoss.zul.Treerow;

import com.cci.zkweb.core.entity.p8.Folder;
import com.cci.zkweb.core.util.ZKFUtils;

/**
 * Folder tree renderer
 * Define the rendering of a tree node
 * @author durzod
 */
public class FolderTreeRenderer 
implements TreeitemRenderer<Folder> {
	@Override
	public void render(Treeitem item, Folder data, int index)
	throws Exception {
		if(data != null) {
			Treerow row = new Treerow();
			row.setParent(item);
			String imageSClass = "";
			if(data.isRoot())
				imageSClass = ZKFUtils.ROOT_FOLDER_CLASS;
	    	else if(data.getChildren() == null || data.getChildren().size() <= 0)
	    		imageSClass = ZKFUtils.EMPTY_FOLDER_CLASS;
	    	else
	    		imageSClass = ZKFUtils.FOLDER_CLASS;

			Treecell cell = new Treecell(data.getName());
			cell.setSclass(imageSClass);
			cell.setParent(row);
			item.setValue(data);
		}
	}
}